﻿using System;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Reflection;
using StevensReceipts.Domain;

namespace StevensReceipts.Repository
{
    public class ReceiptsDbContext  : DbContext
    {
        private const string ConnectionStringName = "DefaultConnection";

        public ReceiptsDbContext() : base(ConnectionStringName)
        {

        }

        public DbSet<Client> Clients { get; set; }
        public DbSet<Address> Addresses { get; set; }
        public DbSet<Business> Businesses { get; set; }
        public DbSet<ChartofAccount> ChartofAccounts { get; set; }
        public DbSet<ChartofAccountAccountType> ChartofAccountAccountTypes { get; set; }
        public DbSet<ChartofAccountCategory> ChartofAccountCategories { get; set; }
        public DbSet<Contact> Contacts { get; set; }
        public DbSet<Receipt> Receipts { get; set; }
        public DbSet<TaxRate> TaxRates { get; set; }

        public DbSet<Invoice> Invoices { get; set; }
        public DbSet<ReceiptItem> ReceiptItems { get; set;}

        public DbSet<UserProfile> UserProfiles { get; set; }

        public DbSet<UserPermissionLine> UserPermissions { get; set; }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();


            //var contextConfiguration = new ContextConfiguration();
            //var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
            //var container = new CompositionContainer(catalog);
            //container.ComposeParts(contextConfiguration);

            //foreach (var configuration in contextConfiguration.Configurations)
            //{
            //    configuration.AddConfiguration(modelBuilder.Configurations);
            //}         

            modelBuilder.Configurations.Add(new UplEntityTypeConfiguration());
            base.OnModelCreating(modelBuilder);
        }
    }
}